<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
    array('op'=>'list','title'=>'提交表单列表'),
);
if($_RQ['op']=='list'){
    $return['shenfentype']=$this->model('model')->shenfentype();
    $params=array();
    $params['uniacid']=$_SESSION['uniacid'];
    if($_RQ['mid']){
        $params['mid']=intval($_RQ['mid']);
        $return['params']['mid']=$_RQ['mid'];
    }
    if(!empty($_RQ['shenfen']) || $_RQ['shenfen']==='0'){
        $shenfen=$return['shenfentype'][$_RQ['shenfen']];
        $params['shenfen like']='%'.$shenfen.'%';
        $return['params']['shenfen']=$_RQ['shenfen'];
    }
    if(!empty($_RQ['sex'])){
        $params['sex']=trim($_RQ['sex']);
        $return['params']['sex']=$_RQ['sex'];
    }
    if(!empty($_RQ['minz'])){
        $params['minz']=trim($_RQ['minz']);
        $return['params']['minz']=$_RQ['minz'];
    }
    if($_RQ['name']){
        $params['name like']='%'.trim($_RQ['name']).'%';
        $return['params']['name']=$_RQ['name'];
    }
	if($_RQ['mobile']){
        $params['mobile like']='%'.trim($_RQ['mobile']).'%';
        $return['params']['mobile']=$_RQ['mobile'];
    }
    if($_RQ['chuangnum']){
        $params['chuangnum like']='%'.trim($_RQ['chuangnum']).'%';
        $return['params']['chuangnum']=$_RQ['chuangnum'];
    }
    //创建时间
    if($_RQ['createtime']){
        $time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
        $time_range=json_decode($time_range,true);
        $params['createtime between']=array($time_range['tstart'],$time_range['tend']);
        $return['params']['createtime']=$time_range;
    }
    $pindex = max(1, intval($_RQ['page']));
    $psize = 10;
    $total='';
    $list=pdo_getslice('jy_formget_message',$params,array($pindex,$psize),$total,$fields,'','id desc');
    if($list){
        foreach($list as &$item){
            $item['member']=cfc('core')->member_show($item['mid']);
        }
    }
    $return['list']=$list;
    $totalpage=ceil($total/$psize);
    $totalpage=intval($totalpage);
    $return['totalpage'] =$totalpage;
    $return['params']['page'] =$pindex;
    $htmls=array(
        'type'=>'list',
        'export'=>'export',
        'tabs'=>$tabs,
        'list'=>array('data'=>'list','tip'=>'[温馨提示]：','edit'=>false,'list'=>array(
            array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'name','title'=>'姓名','type'=>'string'),
			array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
			array('name'=>'minz','title'=>'民族','type'=>'radio','options'=>'minzus'),
			array('name'=>'age','title'=>'年龄','type'=>'string'),
			array('name'=>'code','title'=>'身份证号','type'=>'string'),
			array('name'=>'mobile','title'=>'联系电话','type'=>'string'),
			array('name'=>'address','title'=>'家庭住址','type'=>'string'),
			array('name'=>'yibao','title'=>'医保类型','type'=>'string'),
			array('name'=>'shenfen','title'=>'本人身份','type'=>'string'),
			array('name'=>'peiname','title'=>'被陪护人姓名','type'=>'string'),
            array('name'=>'chuangnum','title'=>'床位号','type'=>'string'),
            array('name'=>'createtime','title'=>'时间','type'=>'time'),
        ),'batch'=>array(
            array('type'=>'api','url'=>'/message/export/isids=1','title'=>'按选择导出'),
        )),
        'search'=>array(
            array('name'=>'shenfen','width'=>10,'title'=>'本人身份','type'=>'radio','options'=>'shenfentype'),
			array('name'=>'name','width'=>10,'title'=>'姓名','type'=>'string'),
			array('name'=>'sex','width'=>10,'title'=>'性别','type'=>'radio','options'=>'sex'),
			array('name'=>'minz','width'=>10,'title'=>'民族','type'=>'radio','options'=>'minzus'),
            array('name'=>'chuangnum','width'=>10,'title'=>'床位号','type'=>'string'),
            array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
            array('name'=>'createtime','width'=>15,'title'=>'提交时间','type'=>'time_range'),
        )
    );
	$return['minzus']=$this->model('model')->minzus();
	$return['yibaotype']=$this->model('model')->yibaotype();

	$return['sex']=array('无','男','女');
    $return['htmls']=$htmls;
    exi($return);
}
if($_RQ['op']=='export'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
    $ids=trim($_RQ['ids'],';');
    if($ids){
        $ids=explode(';',$ids);
        $params['id']=$ids;
    }else{
        if($_RQ['isids']){
            $params['id']=-1;
        }
    }
	if($_RQ['mid']){
        $params['mid']=intval($_RQ['mid']);
        $return['params']['mid']=$_RQ['mid'];
    }
    if(!empty($_RQ['sex'])){
        $params['sex']=trim($_RQ['sex']);
        $return['params']['sex']=$_RQ['sex'];
    }
    if(!empty($_RQ['minz'])){
        $params['minz']=trim($_RQ['minz']);
        $return['params']['minz']=$_RQ['minz'];
    }
    if($_RQ['name']){
        $params['name like']='%'.trim($_RQ['name']).'%';
        $return['params']['name']=$_RQ['name'];
    }
	if($_RQ['mobile']){
        $params['mobile like']='%'.trim($_RQ['mobile']).'%';
        $return['params']['mobile']=$_RQ['mobile'];
    }
    $header=array(
        'id'=>'ID',
        'name'=>'姓名',
		'sex'=>'性别',
		'minz'=>'民族',
		'age'=>'年龄',
		'code'=>'身份证号',
		'mobile'=>'联系电话',
		'address'=>'家庭住址',
		'yibao'=>'医保类型',
		'shenfen'=>'本人身份',
		'peiname'=>'被陪护人姓名',
        'chuangnum'=>'床位号',
		'createtime'=>'时间',
    );
	$minzus=$this->model('model')->minzus();
	$yibaotype=$this->model('model')->yibaotype();
	$shenfentype=$this->model('model')->shenfentype();
	$sex=array('无','男','女');
	$order=pdo_getall('jy_formget_message',$params);
	foreach($order as &$item){
		$item['createtime'] = date('Y-m-d H:i:s',$item['createtime']);
		$member=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('mobile','nickname'));
		$item['sex']=$sex[$item['sex']];
		$item['minz']=$minzus[$item['minz']];
	}
	cfc('tools')->export2excel($header,$order,'表单');
}
if($_RQ['op']=='del'){
    $id=intval($_RQ['id']);
    if($id){
        pdo_delete('jy_formget_message',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
    }
    $del=trim($_RQ['del'],';');
    if($del){
        $del=explode(';',$del);
        foreach($del as $id){
            $id=intval($id);
            if($id){
                pdo_delete('jy_formget_message',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
            }
        }
    }
    exi('删除成功！');
}